//
//  HandInPaymentSuccessVC.m
//  MyNewProject
//
//  Created by sun on 2019/2/15.
//  Copyright © 2019 sun. All rights reserved.
//

#import "HandInPaymentSuccessVC.h"
#import "MyOrderViewController.h"
@interface HandInPaymentSuccessVC ()

@end

@implementation HandInPaymentSuccessVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.gk_navTitle = @"订单支付";
    self.view.backgroundColor = SKColorWithHex(0xF1F1F1);
    [self initView];
}
-(void)initView
{
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake((SCREEN_WIDTH - 93)/2,SKTopBar_Height + 71,93,85.5);
    [self.view addSubview:imageView];
    
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(0,imageView.bottom + 21,SCREEN_WIDTH,20);
    label.numberOfLines = 0;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = SKFONT_Semibold(21);
    label.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];



    [self.view addSubview:label];
    
   
    UILabel *priceLab = [[UILabel alloc] init];
    priceLab.frame = CGRectMake(0,label.bottom  + 20,SCREEN_WIDTH,14);
    priceLab.numberOfLines = 0;
    priceLab.textAlignment = NSTextAlignmentCenter;
    priceLab.font = SKFONT_Semibold(18);
    priceLab.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];


        
   
    UILabel *jiFenLab = [[UILabel alloc] init];
    jiFenLab.frame = CGRectMake(0,priceLab.bottom  + 10,SCREEN_WIDTH,14);
    jiFenLab.numberOfLines = 0;
    jiFenLab.textAlignment = NSTextAlignmentCenter;
    jiFenLab.font = SKFONT_Medium(13);
    jiFenLab.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];




//    NSString * totalAmtStr = @"查看订单";
    UIFont * font = SKFONT_Semibold(18);
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    
    button.frame = CGRectMake((SCREEN_WIDTH -167)/2, jiFenLab.bottom + 18, 167 , 41);
    
    button.imageView.contentMode = UIViewContentModeScaleAspectFit;
    
    button.backgroundColor = SKColorWithHex(0xE33030);
    
    button.titleLabel.font = font ;
    
    [button setTitleColor:SKColorWithHex(0xFFFFFF) forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(lookOrder:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button];
    
    
    NSString * totalAmtStr1 = @"返回首页";

    UIFont * font1 = SKFONT_Semibold(18);
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    
    
    button1.frame = CGRectMake((SCREEN_WIDTH -120)/2, button.bottom + 10, 120 , 41);
    
    
    button1.backgroundColor = [UIColor clearColor];
    
    

    button1.titleLabel.font = font1 ;
    [button1 setTitle:totalAmtStr1 forState:UIControlStateNormal];

    [button1 setTitleColor:SKColorWithHex(0x8888888) forState:UIControlStateNormal];
    
    [button1 addTarget:self action:@selector(backFirstPage:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button1];

    switch (_myOrderState) {
        case OrderStateSuccess:
        {
            imageView.image =[UIImage imageNamed:@"paySuccess"];
            label.text = @"订单支付成功";
            priceLab.text = [NSString stringWithFormat:@"￥%@",self.count];

            [self.view addSubview:priceLab];

            if ([self.type intValue] == 1) {
//                jiFenLab.text = [NSString stringWithFormat:@"获得积分：%@",self.up_jifen];

            }
            else
            {
                jiFenLab.text = [NSString stringWithFormat:@"消耗积分：%@",self.up_jifen];

            }

//            [self.view addSubview:jiFenLab];

            NSString * totalAmtStr1 = @"查看订单";
            [button setTitle:totalAmtStr1 forState:UIControlStateNormal];

        }
            break;
        case OrderStateFailure:
        {
            imageView.image =[UIImage imageNamed:@"payFaile"];
            label.text = @"订单支付失败";


            NSString * totalAmtStr1 = @"再试一次";
            [button setTitle:totalAmtStr1 forState:UIControlStateNormal];

        }
            break;

        default:
            break;
    }
    
}
-(void)lookOrder:(UIButton*)sender
{
    NSArray * vcArray = self.navigationController.viewControllers;
    MyOrderViewController * myOrder = nil;
    for (id VC in vcArray) {
        if ([VC isKindOfClass:[MyOrderViewController class]]) {
            myOrder = VC;
        }
    }
    if (myOrder) {
        [self.navigationController popToViewController:myOrder animated:YES];
    }
    else
    {
        [self.navigationController popToRootViewControllerAnimated:true];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [(UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController setSelectedIndex:2];
        });
    }
}
-(void)backFirstPage:(UIButton*)sender
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
